//
//  myCourceViewController.m
//  One Construction
//
//  Created by apple on 2019/9/10.
//  Copyright © 2019 apple. All rights reserved.
//

#import "myCourceViewController.h"
#import "secondTableViewCell.h"
#import "courceDetailViewController.h"
@interface myCourceViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *TableView;
@property(nonatomic,strong)NSMutableArray *dataArr;

@end

@implementation myCourceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1.0];
    
    self.navigationItem.title = @"我的课程";
    [self requestDataFromNet];
    
    [self.view addSubview: self.TableView ];
    
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 120;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellid = @"mycoursecellid";
    secondTableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:cellid];
    cell.backgroundColor  =[UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1.0];
//        secondModel *model = self.dataArr[indexPath.row];
    
    [cell.headImgView sd_setImageWithURL:[NSURL URLWithString:self.dataArr[indexPath.row][@"pic"]]];
    cell.topLable.text = self.dataArr[indexPath.row][@"bt"];
    cell.studyLable.text = [NSString stringWithFormat:@"%@学习人数",self.dataArr[indexPath.row][@"xx_rs"]];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    //把模型变成数组
    //    NSMutableArray *statusArr  = [secondModel mj_keyValuesArrayWithObjectArray:_dataArr];


    courceDetailViewController *de = [[courceDetailViewController alloc]init];
    de.kc_id  = _dataArr[indexPath.row][@"id"];
    de.bt=_dataArr[indexPath.row][@"bt"];
    de.pic=_dataArr[indexPath.row][@"pic"];
    de.xx_rs=_dataArr[indexPath.row][@"xx_rs"];
    [self.navigationController pushViewController:de animated:YES];
}
-(UITableView *)TableView{
    if (!_TableView) {
        _TableView = [[UITableView alloc]initWithFrame:CGRectMake(0, AppNavitionHright, ScreenWidth, ScreenHeight-TabbarSafetyZone) style:UITableViewStylePlain];
        _TableView.delegate = self;
        _TableView.dataSource = self;
        _TableView.backgroundColor =  [UIColor colorWithRed:246/255.0 green:246/255.0 blue:246/255.0 alpha:1.0];
        [_TableView registerClass:[secondTableViewCell class] forCellReuseIdentifier:@"mycoursecellid"];
        _TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
        
    }
    return _TableView;
}
- (void)requestDataFromNet{
    __weak __typeof__(self)WeakSelf = self;
     NSString *drivice_id  = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    NSDictionary *dic = @{
                          @"lb":@"一级建造师",
                          @"kmlb":@"",
                          @"drivice_id":drivice_id,
                          @"user_id":[User sharedUUser].user_id,
                          @"page":@"",
                          };
    [CZNetWork post:@"https://i.zhongjianedu.com/ios.php/104/classes/listmyclasses3" params:dic success:^(id success) {
      
        NSLog(@"success:%@",success);
        [self.dataArr removeAllObjects];
        NSArray *arry = success[@"classes_list"];
        for (int i =0; i<arry.count; i++) {
            [self.dataArr addObject:arry[i]];
            
        }
        [WeakSelf.TableView reloadData];
    } failure:^(NSError *error) {
        
        
    }];
    
    
    
    
}
-(NSMutableArray *)dataArr{
    if (!_dataArr) {
        _dataArr = [[NSMutableArray alloc]init];
    }
    return _dataArr;
}
@end
